import entity.Order;
import entity.OrderAndId;
import utils.Initialization;
import utils.Outs;
import utils.Regular;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        System.out.println(5 + 5 + "5");

//        lap();

    }

    public static void lap() {
        Scanner scanner = new Scanner(System.in);
        Boolean flag = false;
        HashMap<Integer, Order> hashMap = new HashMap<>();
        ArrayList<Order> arrayList = new ArrayList<>();
        NumberFormat format = NumberFormat.getInstance();

        while (!flag) {
            Outs.out();
            System.out.print("请选择：");
            int nextInt = scanner.nextInt();
            switch (nextInt) {
                case 1:
                    System.out.println("1.我要订餐");
                    System.out.print("请输入订餐人姓名：");
                    String userName = scanner.next();
                    if(Regular.rule(userName)) {

                        try {
                            HashMap<Object, Object> map = Initialization.cp();
                            HashMap<String, Object> mp1 = null;
                            HashMap<String, Object> mp2 = null;
                            HashMap<String, Object> mp3 = null;

                            Object obj1 = map.get("cpHashMap");
                            Object obj2 = map.get("priceHashMap");
                            Object obj3 = map.get("dzHashMap");
                            if (obj1 instanceof HashMap) {
                                mp1 = (HashMap<String, Object>) obj1;
                            }
                            if (obj2 instanceof HashMap) {
                                mp2 = (HashMap<String, Object>) obj2;
                            }
                            if (obj3 instanceof HashMap) {
                                mp3 = (HashMap<String, Object>) obj3;
                            }
                            System.out.println("编号\t\t菜品名称\t\t价格\t\t\t点赞数");
                            HashMap<Integer, OrderAndId> orderAndIdHashMap = new HashMap<>();
                            OrderAndId orderAndId = new OrderAndId();

                            for (int i = 1; i <= map.size(); i++) {
                                System.out.println(i + "\t\t" + mp1.get(i) + "\t\t" + mp2.get(i) + "\t\t" + mp3.get(i));
                                orderAndId.setId(i);
                                orderAndId.setDisMegs(mp1.get(i).toString());
                                Number num = format.parse(mp2.get(i).toString());
                                double nu = num.doubleValue();
                                orderAndId.setSumPrices(nu);
                                orderAndId.setStates(1);
                                Set<Integer> keys = orderAndIdHashMap.keySet();
                                int key = 1;
                                for (Integer ke : keys) {
                                    if(ke > key) {
                                        key = ke;
                                    }
                                }
                                orderAndIdHashMap.put(key,orderAndId);
                            }
                            System.out.print("请选择您要点的菜品编号：");
                            int anInt = scanner.nextInt();
                            System.out.print("请选择您需要的份数：");
                            int FSInt = scanner.nextInt();
                            System.out.print("请输入送餐时间（送餐时间是10点至20点间整点送餐）：");
                            int SCInt = scanner.nextInt();
                            System.out.print("请输入送餐地址：");
                            String DZ = scanner.next();
                            System.out.println(userName + "\t,您订的餐是！" + mp1.get(anInt) + "\t\t" + FSInt + "份");
                            System.out.println("送餐时间：" + SCInt + "点");

                            Object ob = mp2.get(anInt);
                            Object obj = mp3.get(anInt);
                            Number numbe = format.parse(ob.toString());
                            Number number = format.parse(obj.toString());
                            double doubleValu = numbe.doubleValue();
                            double doubleValue = number.doubleValue();
                            System.out.println("餐费：" + (doubleValu * FSInt) + "元\t送餐费:" + (doubleValue * FSInt) + "\t总计：" + ((doubleValu * FSInt) + (doubleValue * FSInt)) + "元");

                            Order order = new Order();
                            Set<Integer> keys = hashMap.keySet();
                            int key = 1;
                            for (Integer ke : keys) {
                                if(ke > key && ke != 1) {
                                    key = ke;
                                } else {
                                    key++;
                                }
                            }
                            order.setId(key);
                            order.setName(userName);
                            order.setDisMegs(orderAndId.getDisMegs());
                            order.setTime(String.valueOf(SCInt));
                            order.setAddress(DZ);
                            order.setStates(1);
                            order.setSumPrices((doubleValu * FSInt) + (doubleValue * FSInt));
                            hashMap.put(key,order);
                            System.out.println("订餐成功！\n");
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    } else {
                        System.out.println("请输入正确的姓名！");
                        break;
                    }

                    break;
                case 2:
                    System.out.println("2.*********查看餐袋*********");
                    if (hashMap.size() <= 0) {
                        Order order1 = new Order(1, "张三", "红烧带鱼", "10:30", "天成路18号", 1, 6.0);
                        Order order2 = new Order(2, "里斯", "红烧猪蹄", "12:30", "天成路18号", 0, 66.3);

                        hashMap.put(order1.getId(), order1);
                        hashMap.put(order2.getId(), order2);
                    }
                    System.out.println("序号\t\t订餐人\t\t餐品信息\t\t送餐日期\t\t送餐地址\t\t总金额\t\t订单状态");
                    for (int i = 0; i < hashMap.size(); i++) {
                        Order o = hashMap.get(i + 1);
                        System.out.println(o.getId() + "\t\t" + o.getName() + "\t\t\t" + o.getDisMegs() + "\t\t" + o.getTime() + "\t\t" + o.getAddress() + "\t" + o.getSumPrices() + "\t\t" + (o.getStates() == 0 ? "已完成" : "已预定"));
                    }
                    System.out.println(" ");
                    break;
                case 3:
                    System.out.println("3.签收订单");
                    System.out.println("序号\t\t订餐人\t\t餐品信息\t\t送餐日期\t\t送餐地址\t\t总金额\t\t订单状态");
                    for (int p = 0; p < hashMap.size(); p++) {
                        Order o = hashMap.get(p + 1);
                        System.out.println(o.getId() + "\t\t" + o.getName() + "\t\t\t" + o.getDisMegs() + "\t\t" + o.getTime() + "\t\t" + o.getAddress() + "\t" + o.getSumPrices() + "\t\t" + (o.getStates() == 0 ? "已完成" : "已预定"));
                    }
                    System.out.print("请选择要签收的订单序号：");
                    int i = scanner.nextInt();
                    if (i <= hashMap.size()) {
                        try {
                            Order order = hashMap.get(i);
                            Order o = new Order();
                            o.setId(order.getId());
                            o.setName(order.getName());
                            o.setDisMegs(order.getDisMegs());
                            o.setTime(order.getTime());
                            o.setAddress(order.getAddress());
                            o.setStates(0);
                            o.setSumPrices(order.getSumPrices());
                            hashMap.put(i, o);

                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }

                        System.out.println("订单签收成功！");
                        Outs.hashMapOut(hashMap);
                        System.out.println();
                    } else {
                        System.out.println("嘻嘻嘻");
                    }
                    break;
                case 4:
                    System.out.println("4.删除订单");
                    Outs.hashMapOut(hashMap);
                    System.out.print("请选择输入要删除的订单编号：");
                    int anInt = scanner.nextInt();
                    if (hashMap.containsKey(anInt)) {
                        Order remove = hashMap.remove(anInt);
                        if(remove != null) {
                            System.out.println("删除成功！");
                        } else {
                            System.out.println("删除失败！");
                        }

                        Outs.hashMapOut(hashMap);
                    } else {
                        System.out.println("嘻嘻嘻");
                    }
                    break;
                case 5:
                    System.out.println("5.我要点赞");

                    try {
                        HashMap<Object, Object> map = Initialization.cp();
                        HashMap<String, Object> mp1 = null;
                        HashMap<String, Object> mp2 = null;
                        HashMap<String, Object> mp3 = null;

                        Object obj1 = map.get("cpHashMap");
                        Object obj2 = map.get("priceHashMap");
                        Object obj3 = map.get("dzHashMap");
                        if (obj1 instanceof HashMap) {
                            mp1 = (HashMap<String, Object>) obj1;
                        }
                        if (obj2 instanceof HashMap) {
                            mp2 = (HashMap<String, Object>) obj2;
                        }
                        if (obj3 instanceof HashMap) {
                            mp3 = (HashMap<String, Object>) obj3;
                        }
                        System.out.println("编号\t\t菜品名称\t\t价格\t\t\t点赞数");
                        HashMap<Integer, OrderAndId> orderAndIdHashMap = new HashMap<>();


                        for (int io = 1; io <= map.size(); io++) {
                            OrderAndId orderAndId = new OrderAndId();
                            orderAndId.setId(io);
                            orderAndId.setDisMegs(mp1.get(io).toString());
                            Number num = format.parse(mp2.get(io).toString());
                            double nu = num.doubleValue();
                            orderAndId.setSumPrices(nu);
                            orderAndId.setStates(1);
                            Set<Integer> keys = orderAndIdHashMap.keySet();
                            int key = io;
                            orderAndIdHashMap.put(key,orderAndId);
                        }
                        for (int j = 0; j < orderAndIdHashMap.size(); j++) {
                            OrderAndId orderAndId1 = orderAndIdHashMap.get(j + 1);
                            System.out.println(orderAndId1.getId() + "\t\t" + orderAndId1.getDisMegs()+ "\t\t" + orderAndId1.getSumPrices() + "\t\t" + orderAndId1.getStates());
                        }

                        System.out.print("请输入您要点赞的订单编号：");
                        int dz = scanner.nextInt();
                        OrderAndId andId = orderAndIdHashMap.get(dz);
                        andId.setStates(andId.getStates() + 1);
                        orderAndIdHashMap.put(andId.getId(),andId);

                        System.out.println("编号\t\t菜品名称\t\t价格\t\t\t点赞数");
                        for (int j = 0; j < orderAndIdHashMap.size(); j++) {
                            OrderAndId orderAndId1 = orderAndIdHashMap.get(j);
                            if(orderAndId1 != null) {
                                System.out.println(orderAndId1.getId() + "\t\t" + orderAndId1.getDisMegs()+ "\t\t" + orderAndId1.getSumPrices() + "\t\t" + orderAndId1.getStates());
                            }
                        }
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }

                    break;
                case 6:
                    flag = true;
                    System.out.println("退出，欢迎下次光临！！！");
                    scanner.close();
                    break;
                default:
                    System.out.println("输入有误");
                    break;
            }
        }
    }




}